package vn.edu.saigontech.ncms.web.bookstore;

import vn.edu.saigontech.ncms.service.UserService;
import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateReturnAction extends AbstractValidator {
	private String date;
	private Long userId;
	
	@Override
	public String check() {
		if(Checker.isEmpty(date)) {
			this.sendKeyError("validator.required", "date");
		}
		if(!Checker.isDate(this.date, this.i18n("format.date"))) {
			this.sendKeyError("validator.invalid", "date");
		}
		if(Checker.isNull(this.userId)) {
			this.sendKeyError("validator.required", "user");
		}
		if(Checker.isNull(UserService.INSTANCE.findById(this.userId))) {
			this.sendKeyError("validator.notExist", "user");
		}
		return this.toSuccess();
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}
}